//
//  YZEMsgcenterTableViewController.m
//  yilutongxing
//
//  Created by T&J on 2017/3/30.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "YZEMsgcenterTableViewController.h"
#import <QMUIKit/QMUIKit.h>
#import "SystemmsgTableViewController.h"
#import "MessageTableViewController.h"

@interface YZEMsgcenterTableViewController ()
@property (nonatomic, strong) UIButton *redot_mymsg;
@property (nonatomic, strong) UIButton *redot_sysmsg;

@property (nonatomic, strong) NSDictionary *sysmsgDic;//系统消息
@property (nonatomic, strong) NSDictionary *commentDic;//评论消息
@end

@implementation YZEMsgcenterTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title = @"消息中心";
    
    //回复我的
    _redot_mymsg = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-60, 11, 28, 28)];
    _redot_mymsg.layer.cornerRadius = 28/2;
    _redot_mymsg.layer.masksToBounds = 28/2;
    [_redot_mymsg setBackgroundImage:[UIImage imageNamed:@"提醒"] forState:UIControlStateNormal];
    [_redot_mymsg setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_redot_mymsg setTitle:@"6" forState:UIControlStateNormal];
    [_redot_mymsg.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [_m_cell_mymsg.contentView addSubview:_redot_mymsg];
    _redot_mymsg.hidden = YES;//暂时隐藏
    //系统消息
    _redot_sysmsg = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-60, 11, 28, 28)];
    _redot_sysmsg.layer.cornerRadius = 28/2;
    _redot_sysmsg.layer.masksToBounds = 28/2;
    [_redot_sysmsg setBackgroundImage:[UIImage imageNamed:@"提醒"] forState:UIControlStateNormal];
    [_redot_sysmsg setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_redot_sysmsg setTitle:@"6" forState:UIControlStateNormal];
    [_redot_sysmsg.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [_m_cell_sysmsg.contentView addSubview:_redot_sysmsg];//暂时隐藏
    _redot_sysmsg.hidden = YES;
    
    for (NSDictionary *model in self.unreadArr) {
        if ([model[@"model"] isEqualToString:@"SYSTEM_MESSAGE"]) {
            self.sysmsgDic = model;
        }
        else if ([model[@"model"] isEqualToString:@"COMMENT_MESSAGE"]) {
            self.commentDic = model;
        }
    }
    
    [self setMsgNum:@"sysmsg" amount:[((NSNumber*)_sysmsgDic[@"unreadCount"]) intValue]];
    [self setMsgNum:@"mymsg" amount:[((NSNumber*)_commentDic[@"unreadCount"]) intValue]];
}

//设置消息数目
-(void)setMsgNum:(NSString*)msgtype amount:(NSInteger)amount{
    if ([msgtype compare:@"mymsg"]==NO) {
        if (amount==0) {
            _redot_mymsg.hidden = YES;
        }
        else {
            _redot_mymsg.hidden = NO;
            [_redot_mymsg setTitle:[NSString stringWithFormat:@"%d",(int)amount] forState:UIControlStateNormal];
        }
    }
    else if([msgtype compare:@"sysmsg"]==NO){
        if (amount==0) {
            _redot_sysmsg.hidden = YES;
        }
        else {
            _redot_sysmsg.hidden = NO;
            [_redot_sysmsg setTitle:[NSString stringWithFormat:@"%d",(int)amount] forState:UIControlStateNormal];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
            MessageTableViewController *v = [MessageTableViewController new];
            [self.navigationController pushViewController:v animated:YES];
        }
            break;
            
        default:
        {
            SystemmsgTableViewController *v = [SystemmsgTableViewController new];
            [self.navigationController pushViewController:v animated:YES];
        }
            break;
    }
}


@end
